#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

unordered_map<ll,int> f;
unordered_map<ll,bool> g;

const int N = 12;
const int inf = 0x3f3f3f3f;

int t[N],a[N][N],b[N][N],n,m;

ll encode(){
	ll s = 0;
	for(int i = 1;i <= n;i++) s = s * 12 + t[i];
	return s;
}

void decode(ll s){
	for(int i = n;i >= 1;i--) t[i] = s % 12,s /= 12;
}

int dfs(ll x,bool who){
	if(g[x]) return f[x];
	decode(x); int tot = who ? inf : -inf;
	for(int i = 1;i <= n;i++){
		if(t[i] < t[i-1]){
			t[i]++; ll news = encode();
			if(!who) tot = max(tot,dfs(news,who^1) + a[i][t[i]]);
			else tot = min(tot,dfs(news,who^1) - b[i][t[i]]);
			t[i]--;
		}
	}
	g[x] = 1;f[x] = tot;return tot;
}
			
int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) a[i][j] = in;
	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) b[i][j] = in;
	for(int i = 0;i <= n;i++) t[i] = m;
	ll st = encode();
	g[st] = 1; f[st] = 0;
	int ans = dfs(0,0);
	printf("%d\n",ans);
	return 0;
}

